package com.shop.front.dao.user;


import com.shop.jpa.BaseSQLDao;
import com.shop.jpa.support.QuerySQL;
import com.shop.domain.user.UserAddress;
import com.shop.web.context.WebContext;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Repository;

@Repository
public class UserAddressSQLDao extends BaseSQLDao {

    public Page<UserAddress> page(Long userId) {
        StringBuffer field = new StringBuffer("ua.*");
        String from = "t_user_address ua";
        String order = "ua.is_default desc, ua.id desc";
        QuerySQL qs = new QuerySQL(WebContext.getPageNo(), WebContext.getPageSize(), field.toString(), from, order);
        qs.addWhereWithoutParams("ua.is_deleted = 0");
        qs.addWhereEq("ua.uid", userId);
        return this.page(qs, UserAddress.class);
    }

}
